﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using JM.JCY.BusinessEntity;
using JM.JCY.Proxy;
using Microsoft.SharePoint;

namespace JM.JCY.SharePointComponent.StaffContact.StaffContactSearch
{
    public partial class StaffContactSearchUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GridViewDataBind();
            }
        }

        protected void imgCancel_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect(SPContext.Current.Web.Url);
        }

        protected void gvStaffContact_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.gvStaffContact.PageIndex = e.NewPageIndex;
            GridViewDataBind();
        }

        private void GridViewDataBind()
        {
            using (UserManagementProxy proxy = new UserManagementProxy())
            {
                var dt = proxy.GetUserContactByName(string.Empty);
                this.gvStaffContact.DataSource = dt;
                this.gvStaffContact.DataBind();
            }
        }

        protected void imgSearch_Click(object sender, ImageClickEventArgs e)
        {
            string searchname = this.txtName.Text.Trim();
            using (UserManagementProxy proxy = new UserManagementProxy())
            {
                var dt = proxy.GetUserContactByName(searchname);
                this.gvStaffContact.DataSource = dt;
                this.gvStaffContact.DataBind();
            }

        }
    }
}
